Imports System.Data

Partial Class Reportes_Controls_ctlRptCarnetEmitido
    Inherits System.Web.UI.UserControl
    Dim dato As String
    Dim sError As String = ""

    Public Sub ShowReport()
        Dim objReporte As New BusinessLogic.crPersona
        Dim objCarnetEmitido As New DataTable
        Dim fechainicio As String = ""
        Dim fechafinal As String = ""
        Dim codMembresia As String = ""
        If chkFechas.Checked = True Then
            fechainicio = Me.txtStartDate.Value()
            fechafinal = Me.txtEndDate.Value()
        Else
            codMembresia = txtCodMembresia.Text
        End If
        objCarnetEmitido = objReporte.GetReporteCarnetEmitido(codMembresia, fechainicio, fechafinal).Tables(0)
        gridReporteCarnet.DataSource = objCarnetEmitido
        gridReporteCarnet.DataBind()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
        End If
    End Sub

    Public Sub ShowReportFromFilter()
        lblMensaje.Visible = False
        If valida(sError) = True Then
            Me.ShowReport()
        Else
            lblMensaje.Text = sError
            lblMensaje.Visible = True
        End If
    End Sub

    Protected Sub chkFechas_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If chkFechas.Checked = True Then
            Me.txtStartDate.Enabled = True
            Me.txtEndDate.Enabled = True
            chkMembresia.Checked = False
            txtCodMembresia.Text = ""
            txtCodMembresia.Enabled = False
        Else
            Me.txtStartDate.Enabled = False
            Me.txtEndDate.Enabled = False
        End If
        ShowReport()
    End Sub

    Protected Sub chkMembresia_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If chkMembresia.Checked = True Then
            chkFechas.Checked = False
            txtCodMembresia.Enabled = True
            Me.txtStartDate.Enabled = False
            Me.txtEndDate.Enabled = False
        Else
            txtCodMembresia.Enabled = False
            txtCodMembresia.Text = ""
        End If
        ShowReport()
    End Sub

    Protected Sub btnExportar_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ASPxGridViewExport.WriteXlsToResponse()
    End Sub

    Protected Sub btnImprimir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnImprimir.Click
        ASPxGridViewExport.WritePdfToResponse()
    End Sub

    Function valida(ByRef sError As String) As Boolean
        valida = False
        If txtStartDate.Value > Now() Then
            sError = "Fecha Inicial no puede ser mayor a la actual"
        End If
        If txtEndDate.Value > Now() Then
            sError = "Fecha Final no puede ser mayor a la actual"
        End If
        If txtEndDate.Value > txtStartDate.Date Then
            sError = "Fecha Final no puede ser mayor a la Fecha inicial"
        End If
        valida = True
    End Function

    Protected Sub btnMostrar_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ShowReport()
    End Sub

End Class
